package com.example.demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 系统配置文件
 */
@Configuration
public class MyConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginIntercept())
                .addPathPatterns("/**")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/reg")
                .excludePathPatterns("/art/getlistbypage")
                .excludePathPatterns("/art/detail")
                .excludePathPatterns("/editor.md/*")
                .excludePathPatterns("/img/*")
                .excludePathPatterns("/js/*")
                .excludePathPatterns("/css/*")
                .excludePathPatterns("/blog_content.html")
                .excludePathPatterns("/blog_list.html")
                .excludePathPatterns("/login.html")
                .excludePathPatterns("/checkcode/**")
                .excludePathPatterns("/art/Test")
                .excludePathPatterns("/reg.html");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry){
        // 本地
        //registry.addResourceHandler("/img/photo/**").addResourceLocations("file:D:/bitStudy/bit_java/blog_sm_Photo/");
        // 部署
        registry.addResourceHandler("/img/photo/**").addResourceLocations("file:" + System.getProperty("user.dir") + "/blog_sm_Photo/");
    }
}
